// var length = 7;                             // 数字
// var lastName = "Gates";                      // 字符串
// var cars = ["Porsche", "Volvo", "BMW"];         // 数组
// var x = {firstName:"Bill", lastName:"Gates"};    // 对象
$(function () {

    getNewsForHomePageData();

})

function getNewsForHomePageData() {
    $.ajax({
        url: '../json/newsForHomePage.json',
        data: '',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            setNewsForHomePageData(res);
        }
    })
}

function setNewsForHomePageData(res) {
    let str = '';
    for (let i = 0; i < res.length; i++) {
        str += '                        <div>\n' +
            '                            <!--                            字符不应该换行-->\n' +
            '                            <div onclick="toNewsDetailPage(' + res[i].id + ')" class="single-over font-title">' + res[i].title + '\n' +
            '\n' +
            '                            </div>\n' +
            '                            <div class="single-over font-title">' + res[i].content + '</div>\n' +
            '                        </div>';
    }
    $("#news").html(str)
}

function toNewsDetailPage(id) {
    sessionStorage.setItem("newsId", id);
    window.open("newsDetail.html", "_self");
}
